package map.terrain;

import loadsave.Memento;
import loadsave.loadsaveobject.Iterator;
import loadsave.loadsaveobject.LoadSaveObject;
import loadsave.loadsaveobject.LoadSaveObjectComposite;
import loadsave.loadsaveobject.LoadSavePrimitive;
import model.ModelObject;

public abstract class Terrain extends ModelObject {
	
	private int flyingCost;
	private int swimmingCost;
	private int walkingCost;
	
	public Terrain(String name) {
		
		super(name);
	}
	
	public int getFlyingCost() {
		
		return flyingCost;
	}
	
	public int getSwimmingCost() {
		
		return swimmingCost;
	}
	
	public int getWalkingCost() {
		
		return walkingCost;
	}
	
	protected void setFlyingCost(int flyingCost) {
		
		this.flyingCost = flyingCost;
	}
	
	protected void setSwimmingCost(int swimmingCost) {
		
		this.swimmingCost = swimmingCost;
	}
	
	protected void setWalkingCost(int walkingCost) {
		
		this.walkingCost = walkingCost;
	}
	
	public String toString() {
		
		return "Terrain: ";
	}
	
	@Override
	public Memento getMemento() {
		return new Memento() {

			@Override
			public LoadSaveObject getState() {
				LoadSaveObjectComposite toReturn = new LoadSaveObjectComposite("", getName());
				Iterator<LoadSaveObject> i = Terrain.super.getMemento().getState().getIterator();
				for (i.init(); i.hasNext(); i.next()) {
					toReturn.add(i.getCurrKey().getValue(), i.getCurrVal());
				}
				toReturn.add("flyingCost", new LoadSavePrimitive("flyingCost", "int", String.valueOf(flyingCost)));
				toReturn.add("swimmingCost", new LoadSavePrimitive("swimmingCost", "int", String.valueOf(flyingCost)));
				toReturn.add("walkingCost", new LoadSavePrimitive("walkingCost", "int", String.valueOf(flyingCost)));
				return toReturn;
			}

			@Override
			public void restoreState(LoadSaveObject lso) {
				Terrain.super.getMemento().restoreState(lso);
				flyingCost = Integer.valueOf(lso.get("flyingCost").getValue());
				walkingCost = Integer.valueOf(lso.get("walkingCost").getValue());
				swimmingCost = Integer.valueOf(lso.get("swimmingCost").getValue());
			}
			
		};
	}
}
